<?php
/** 
 * @category		
 * @package		Lib			
 * @subpackage	Model.Base.View	
 * @author		wanght <whtaok@gmail.com>
 * @since		2013-3-2
 * @version		$Id: AccessMenuViewModel.class.php 35 2013-03-05 14:35:28Z whtaok@gmail.com $
 */
class AccessMenuViewModel extends ViewModel{
	//视图模型
	public $viewFieldsUser = array(
		'base_admin_accessmenu'=>array(
			'role_id',
			'menu_id'
			),
		'base_admin_menu'=>array(
			'title'		=>'menu_title',
			'type'		=>'menu_type',
			'pid'		=>'menu_pid',
			'ordlist'	=>'menu_ordlist',
			'is_valid'	=>'menu_is_valid',
			'_on'		=>'base_admin_accessmenu.menu_id=base_admin_menu.id'
			),
		'base_admin_node'=>array(
			'title'		=>'node_title',
			'group_name',
			'module_name',
			'action_name',
			'action_params',
			'ordlist'=>'node_ordlist',
			'_on'=>'base_admin_menu.node_id=base_admin_node.id'),
	);

	public $viewFieldsAdmin = array(	
		'base_admin_menu'=>array(
			'id'		=>'menu_id',
			'title'		=>'menu_title',
			'type'		=>'menu_type',
			'pid'		=>'menu_pid',
			'is_valid'	=>'menu_is_valid',
			'ordlist'	=>'menu_ordlist',
		),
		'base_admin_node'=>array(
			'title'=>'node_title',
			'group_name',
			'module_name',
			'action_name',
			'action_params',
			'ordlist'=>'node_ordlist',
			'_on'=>'base_admin_menu.node_id=base_admin_node.id'),
	);
	//is_valid 1:未审核 2：已审核 3：已撤销 4：已删除
	public function getMenuByRoleId($role_id,$menu_type){
		if($role_id===C('ADMIN_ROLE_ID')){
			$this->viewFields = $this->viewFieldsAdmin;
			$data = $this->field('menu_id,menu_pid,menu_title,node_title,group_name,module_name,action_name,action_params,menu_ordlist,node_ordlist')
				->where("role_id = {$role_id}")
				->where("type = '{$menu_type}'")
				->where("base_admin_menu.is_valid = 2")
				->order('menu_ordlist ,node_ordlist')
				->select();
		}else{
			$this->viewFields = $this->viewFieldsUser;
			$data = $this->field('menu_id,menu_pid,menu_title,node_title,group_name,module_name,action_name,action_params,menu_ordlist,node_ordlist')
				->where("type = '{$menu_type}'")
				->where("base_admin_menu.is_valid = 2")
				->order('menu_ordlist ,node_ordlist')
				->select();
		}

		return $data;
	}

}

?>